﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZeroBugBounce.Missive;

namespace ConsoleTestClient
{
	public class Examples
	{
		public void Most_basic_use()
		{
			var messenger = new Messenger();

			// register a handler
			messenger.Handle<int>(m =>
			{
				// runs on a different thread
				// when message received
				Console.WriteLine("message value: {0}", m);
			});

			// send a message to that handler:
			messenger.Send(11);

			// wait for handler to finish in (optional)
			messenger.Dispatcher.WaitAll();
		}

		public void Separate_handlers_by_topic()
		{
			var messenger = new Messenger();

			// register a handler on the default topic:
			messenger.Handle<object>(m =>
			{
				Console.WriteLine("Default topic message: {0}", m);
			});

			// register a handler for specific topic:
			messenger.Handle<object>("MyTopic", m =>
			{
				Console.WriteLine("MyTopic message: {0}", m);
			});

			messenger.Send("I should go to default");
			messenger.Send("MyTopic", "I should go to MyTopic");

			messenger.Dispatcher.WaitAll();
		}
	}
}
